home *** CD-ROM | disk | FTP | other *** search
- /*
- * FILE: morestr.c
- * AUTHOR: R. Gonzalez
- * CREATED: Sept 1, 1990
- *
- * Defines more useful string functions.
- */
-
- # include <stdio.h>
- # include <string.h>
- # include <stdlib.h>
- # include "morestr.h"
-
- # define MAX_LENGTH 80
-
- /************************************************************************
- * Usual function to get line from std. input. Returns number of chars
- * read or EOF.
- ************************************************************************/
- int get_line(FILE *file,char line[],int max_length)
- {
- int c,
- i=0;
-
- while (((c = fgetc(file)) != '\n') && c != EOF)
- if (i < max_length - 1)
- line[i++] = c;
-
- line[i] = '\0';
-
- if (c == EOF)
- return EOF;
- else
- return i;
- }
-
- /************************************************************************
- * converts string to integer. ascii only.
- ************************************************************************/
- int strtoint(char *s)
- {
- int i = 0,
- result = 0;
-
- while (s[i] == ' ')
- i++; /* strip leading spaces */
-
- while (s[i] > 47 && s[i] < 58)
- {
- result = result*10 + s[i] - 48;
- i++;
- }
-
- return result;
- }
-
- /************************************************************************
- * caseless version of strcmp() - only compares up to length of s2.
- * ascii only.
- ************************************************************************/
- boolean strsame(char *s1,char *s2)
- {
- int i;
- char c1,
- c2;
- boolean equal = TRUE;
-
- if (strlen(s1) < strlen(s2))
- equal = FALSE;
- else
- for (i=0 ; i<strlen(s2) ; i++)
- {
- if (s1[i] > 64 && s1[i] < 91)
- c1 = s1[i] + 32; /* convert to lower-case */
- else
- c1 = s1[i];
- if (s2[i] > 64 && s2[i] < 91)
- c2 = s2[i] + 32; /* convert to lower-case */
- else
- c2 = s2[i];
- if (c1 != c2)
- equal = FALSE;
- }
-
- return equal;
- }
-
-
-